package com.ruoyi.project.cardbox.outbound.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.project.cardbox.inbound.domain.OrderInbound;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cardbox.outbound.domain.OrderOutbound;
import com.ruoyi.project.cardbox.outbound.service.IOrderOutboundService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出库单Controller
 * 
 * @author ruoyi
 * @date 2025-07-04
 */
@Controller
@RequestMapping("/cardbox/outbound")
public class OrderOutboundController extends BaseController
{
    private String prefix = "cardbox/outbound";

    @Autowired
    private IOrderOutboundService orderOutboundService;

    @RequiresPermissions("cardbox:outbound:view")
    @GetMapping()
    public String outbound()
    {
        return prefix + "/outbound";
    }

    /**
     * 查询出库单列表
     */
    @RequiresPermissions("cardbox:outbound:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderOutbound orderOutbound)
    {
        startPage();
        List<OrderOutbound> list = orderOutboundService.selectOrderOutboundList(orderOutbound);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @RequiresPermissions("cardbox:outbound:export")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderOutbound orderOutbound)
    {
        List<OrderOutbound> list = orderOutboundService.selectOrderOutboundList(orderOutbound);
        ExcelUtil<OrderOutbound> util = new ExcelUtil<OrderOutbound>(OrderOutbound.class);
        List<String> footer = Arrays.asList(
                " 说明: ",
                " 按规定的附件配置生产；",
                " 纸板平整，不弯曲或折叠；",
                " 压紧到位，不隐藏包。"
        );

        return util.exportExcelWithFooter(list, "出库单数据", "出库单数据", footer);
//        return util.exportExcel(list, "出库单数据");
    }
    /**
     * 导出选中的出库单数据
     */
    @RequiresPermissions("cardbox:outbound:export")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelected")
    @ResponseBody
    public AjaxResult exportSelected(@RequestParam("ids") List<String> ids) {
        List<OrderOutbound> list = orderOutboundService.selectOrderOutboundByIds(ids);
        ExcelUtil<OrderOutbound> util = new ExcelUtil<>(OrderOutbound.class);
        List<String> footer = Arrays.asList(
                " 说明: ",
                " 按规定的附件配置生产；",
                " 纸板平整，不弯曲或折叠；",
                " 压紧到位，不隐藏包。"
        );

        return util.exportExcelWithFooter(list, "出库单数据", "出库单数据", footer);
//        return util.exportExcel(list, "入库单数据");
    }


//    /**
//     * 新增出库单
//     */
//    @RequiresPermissions("cardbox:outbound:add")
//    @GetMapping("/add")
//    public String add()
//    {
//        return prefix + "/add";
//    }
//
//    /**
//     * 新增保存出库单
//     */
//    @RequiresPermissions("cardbox:outbound:add")
//    @Log(title = "出库单", businessType = BusinessType.INSERT)
//    @PostMapping("/add")
//    @ResponseBody
//    public AjaxResult addSave(OrderOutbound orderOutbound)
//    {
//        return toAjax(orderOutboundService.insertOrderOutbound(orderOutbound));
//    }

    /**
     * 修改出库单
     */
    @RequiresPermissions("cardbox:outbound:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OrderOutbound orderOutbound = orderOutboundService.selectOrderOutboundById(id);
        mmap.put("orderOutbound", orderOutbound);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库单
     */
    @RequiresPermissions("cardbox:outbound:edit")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderOutbound orderOutbound)
    {
        return toAjax(orderOutboundService.updateOrderOutbound(orderOutbound));
    }

    /**
     * 删除出库单
     */
    @RequiresPermissions("cardbox:outbound:remove")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderOutboundService.deleteOrderOutboundByIds(ids));
    }
}
